﻿namespace S7.Net.Types
{
    using System;

    public static class Timer
    {
        public static double FromByteArray(byte[] bytes)
        {
            double num = 0.0;
            num = (bytes[0] & 15) * 100.0;
            num += ((bytes[1] >> 4) & 15) * 10.0;
            num += (bytes[1] & 15) * 1.0;
            switch (((bytes[0] >> 4) & 3))
            {
                case 0:
                    return (num * 0.01);

                case 1:
                    return (num * 0.1);

                case 2:
                    return (num * 1.0);

                case 3:
                    return (num * 10.0);
            }
            return num;
        }

        public static double[] ToArray(byte[] bytes)
        {
            double[] numArray = new double[bytes.Length / 2];
            int num = 0;
            for (int i = 0; i < (bytes.Length / 2); i++)
            {
                byte[] buffer1 = new byte[] { bytes[num++], bytes[num++] };
                numArray[i] = FromByteArray(buffer1);
            }
            return numArray;
        }

        public static byte[] ToByteArray(ushort[] value)
        {
            ByteArray array = new ByteArray();
            foreach (ushort num2 in value)
            {
                array.Add(ToByteArray(num2));
            }
            return array.array;
        }

        public static byte[] ToByteArray(ushort value)
        {
            byte[] buffer1 = new byte[2];
            buffer1[1] = (byte) (value & 0xff);
            buffer1[0] = (byte) ((value >> 8) & 0xff);
            return buffer1;
        }
    }
}

